package com.sumainfor.pc.gmio.controller.director;

import com.sumainfor.common.util.JsonResult;
import com.sumainfor.common.utlis.PageUtils;
import com.sumainfor.common.utlis.Pager;
import com.sumainfor.pc.gmio.service.DiTenantBillService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * 租后主管 账单
 */
@RestController
@RequestMapping("/director/TenantBill")
public class DiTenantBillController implements Serializable {
    @Autowired
    private DiTenantBillService diTenantBillService;

    /**
     * 查询账单列表
     *
     * @param params
     * @param pager
     * @return
     */
    @PostMapping("/getTenantBillList")
    public JsonResult getTenantBillList(@RequestBody Map<String, Object> params, Pager pager) {
//        pager.setPageno(Integer.parseInt(params.get("pageno").toString()));
//        pager.setPagesize(Integer.parseInt(params.get("pagesize").toString()));
//
//        JsonResult result=new JsonResult();
//        pager.setPagerNecessary(params, pager);
//        PageUtils pageUtils = new PageUtils();
//        //只有水电燃账单才根据水电燃去查询相对应的水电燃
//        if(FieldCheckUtil.isMapFieldNotNull(params,new String[]{"utilityFeeRadio1"})){
//            //如果水电燃查询，是全部，就清空，相对应查询全部
//            if(params.get("utilityFeeRadio1").toString().equals("0")){
//                params.put("utilityFeeRadio1",null);
//            }
//            //如果不是水电燃类型。就清空水电燃字段
//            if(!params.get("BiType").toString().equals("2")){
//                params.put("utilityFeeRadio1",null);
//            }
//        }
//
//
//      Integer cout=diTenantBillService.getTenantBillListCount(params);
//        if(cout==0){
//            return pageUtils.getJsonResult(new ArrayList<Map<String,Object>>(), params,cout);
//        }
//        List<Map<String,Object>>getCommunityList=diTenantBillService.getTenantBillList(params);
//        result=pageUtils.getJsonResult(getCommunityList, params, cout);
//        return result;
        return diTenantBillService.getTenantBillList(params, pager);
    }

    /**
     * 通过客户编号查询历史账单列表
     *
     * @param params
     * @param pager
     * @return
     */
    @GetMapping("/getTenantBillListByTenIdl")
    public JsonResult getTenantBillListByTenIdl(@RequestParam Map<String, Object> params, Pager pager) {
        JsonResult result = new JsonResult();
        pager.setPagerNecessary(params, pager);
        PageUtils pageUtils = new PageUtils();
        Integer cout = diTenantBillService.getTenantBillListCountByTenId(params);
        if (cout == 0) {
            return pageUtils.getJsonResult(new ArrayList<Map<String, Object>>(), params, cout);
        }
        List<Map<String, Object>> getCommunityList = diTenantBillService.getTenantBillListByTenId(params);
        result = pageUtils.getJsonResult(getCommunityList, params, cout);
        return result;
    }

    /**
     * 通过客户编号查询剩余未缴费账单和待审核账单
     */
    @GetMapping("/getTenantBillListByTenIdwd")
    public JsonResult getTenantBillListByTenIdwd(@RequestParam Map<String, Object> params) {
        JsonResult result = new JsonResult();
        List<Map<String, Object>> list = diTenantBillService.getTenantBillListByTenId(params);
        if (list != null) {
            result.put(list);
        } else {
            result.putFailed("服务器繁忙");
        }
        return result;
    }

    /**
     * 查询逾期账单
     *
     * @param params
     * @param pager
     * @return
     */
    @GetMapping("/getDiTenantBillListByTenIdwd")
    public JsonResult getDiTenantBillListByTenIdwd(@RequestParam Map<String, Object> params, Pager pager) {
        JsonResult result = new JsonResult();
        pager.setPagerNecessary(params, pager);
        PageUtils pageUtils = new PageUtils();
        Integer cout = diTenantBillService.getDiTenantBillListCountByTenIdwd(params);
        if (cout == 0) {
            return pageUtils.getJsonResult(new ArrayList<Map<String, Object>>(), params, cout);
        }
        List<Map<String, Object>> getCommunityList = diTenantBillService.getDiTenantBillListByTenIdwd(params);
        result = pageUtils.getJsonResult(getCommunityList, params, cout);
        return result;
    }

    /**
     * 租后主管 账单审核 根据账单编号查询详情信息
     */
    @GetMapping("/getDiTenantBillInfo")
    public JsonResult getDiTenantBillInfo(@RequestParam Map<String, Object> params, Pager pager) {
        return diTenantBillService.getDiTenantBillInfo(params);
    }

    /**
     * 租后主管查询日账核对列表 收入账单
     *
     * @param params
     * @param pager
     * @return
     */
    @PostMapping("/getDiBillInlCheckList")
    public JsonResult getDiBillInlCheckList(@RequestBody Map<String, Object> params, Pager pager) {
        return diTenantBillService.getDiBillInlCheckList(params, pager);
    }
}
